<template>
	<view class="">
		<u-button @click="getLocal">获取定位</u-button>
		<view class="">
			{{local.lat}}--{{local.long}}
		</view>
	</view>
	
	
</template>

<script>
	export default{
		data(){
			return {
				local:{
					lat:"",
					long:""
				}
			}
		},
		onLoad(e) {
			
		},
		methods:{
			getLocal(){
				let that = this;
				uni.authorize({
					scope:'scope.userLocation',
					success(res) {
						uni.getLocation({
							type:'gcj02',
							success(res) {
								console.log(res);
								const lat = res.latitude;
								const longitude = res.longitude;
								that.local.lat = lat;
								that.local.long = longitude;
								let local={
									lat:that.local.lat,
									longitude:that.local.long
								}
								that.$store.commit("SET_LOCAL",local);
							}
						})
					},
					fail(err) {
						uni.showModal({
							title:'是否开启',
							content:'当前要获取的地理位置',
							showCancel:false,
							success(res) {
								if(res.confirm){
									uni.openSetting({
										success(res) {
											if(res.authSetting['scope.userLocation']){
												//接口请求操作或者其他赋值操作
											}else{
												uni.showToast({
													title:'无法获取最近定位信息',
													duration:2000,
													icon:'none'
												})
											}
										}
									})
								}
							}
						})
					}
				})
			}
		}
		
	}
</script>

<style>
</style>